// SFPSG_BPA.cpp: implementation of the CSFPSG_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/SFPSG_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSFPSG_BPA::CSFPSG_BPA()
{
	m_chType = 'S';
	m_chSubType = 'F';
	m_chChangeCode = ' ';

	m_dKqv = 0;
	m_dTqv = 0;
	m_dKqs = 0;
	m_dTqs = 0;
	m_dTq = 0;
	m_dTq1 = 0;
	m_dTq1_1 = 0;
	m_dTq2 = 0;
	m_dTq2_1 = 0;
	m_dTq3 = 0;
	m_dTq3_1 = 0;
	m_dVsmax = 0;
	m_dVcutoff = 0;
	m_dVslow = 0;
	m_dRBkV = 0;

	memset(m_strRBName,' ',8);
	m_strRBName[8] = '\0';

	m_strCardType[0] = 'S';

}

CSFPSG_BPA::CSFPSG_BPA(CSFPSG_BPA &sfpsgBPA):CUnit_BPA(sfpsgBPA)
{
	m_dKqv = sfpsgBPA.m_dKqv;
	m_dTqv = sfpsgBPA.m_dTqv;
	m_dKqs = sfpsgBPA.m_dKqs;
	m_dTqs = sfpsgBPA.m_dTqs;
	m_dTq = sfpsgBPA.m_dTq;
	m_dTq1 = sfpsgBPA.m_dTq1;
	m_dTq1_1 = sfpsgBPA.m_dTq1_1;
	m_dTq2 = sfpsgBPA.m_dTq2;
	m_dTq2_1 = sfpsgBPA.m_dTq2_1;
	m_dTq3 = sfpsgBPA.m_dTq3;
	m_dTq3_1 = sfpsgBPA.m_dTq3_1;
	m_dVsmax = sfpsgBPA.m_dVsmax;
	m_dVcutoff = sfpsgBPA.m_dVcutoff;
	m_dVslow = sfpsgBPA.m_dVslow;
	m_dRBkV = sfpsgBPA.m_dRBkV;

	strcpy(m_strRBName,sfpsgBPA.m_strRBName);
}

CSFPSG_BPA::~CSFPSG_BPA()
{

}

bool CSFPSG_BPA::FillEx(char *buffer)
{
	int i;

	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSFPSG_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dKqv = StrToDouble(&buffer[16],4,3);
	if(EndOfSec(&buffer[16],4))
		return true;

	m_dTqv = StrToDouble(&buffer[20],3,3);
	if(EndOfSec(&buffer[20],3))
		return true;

	m_dKqs = StrToDouble(&buffer[23],4,3);
	if(EndOfSec(&buffer[23],4))
		return true;

	m_dTqs = StrToDouble(&buffer[27],3,3);
	if(EndOfSec(&buffer[27],3))
		return true;

	m_dTq = StrToDouble(&buffer[30],4,2);
	if(EndOfSec(&buffer[30],4))
		return true;

	m_dTq1 = StrToDouble(&buffer[34],4,3);
	if(EndOfSec(&buffer[34],4))
		return true;

	m_dTq1_1 = StrToDouble(&buffer[38],4,3);
	if(EndOfSec(&buffer[38],4))
		return true;

	m_dTq2 = StrToDouble(&buffer[42],4,3);
	if(EndOfSec(&buffer[42],4))
		return true;

	m_dTq2_1 = StrToDouble(&buffer[46],4,3);
	if(EndOfSec(&buffer[46],4))
		return true;

	m_dTq3 = StrToDouble(&buffer[50],4,3);
	if(EndOfSec(&buffer[50],4))
		return true;

	m_dTq3_1 = StrToDouble(&buffer[54],4,3);
	if(EndOfSec(&buffer[54],4))
		return true;

	m_dVsmax = StrToDouble(&buffer[58],4,3);
	if(EndOfSec(&buffer[58],4))
		return true;

	m_dVcutoff = StrToDouble(&buffer[62],4,3);
	if(EndOfSec(&buffer[62],4))
		return true;

	m_dVslow = StrToDouble(&buffer[66],2,2);
	if(EndOfSec(&buffer[66],2))
		return true;

	for(i=0;i<8;i++)
	{
		if(!buffer[68+i])
			break;
		else
			m_strRBName[i] = buffer[68+i];
	}
	m_strRBName[8] = '\0';
	if(i!=8)
		return true;

	m_dRBkV = StrToDouble(&buffer[76],4,0);
	if(EndOfSec(&buffer[76],4))
		return true;

	return true;
}

bool CSFPSG_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSFPSG_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dKqv,&buffer[16],4,3);
	DoubleToStr(m_dTqv,&buffer[20],3,3);
	DoubleToStr(m_dKqs,&buffer[23],4,3);
	DoubleToStr(m_dTqs,&buffer[27],3,3);
	DoubleToStr(m_dTq,&buffer[30],4,2);
	DoubleToStr(m_dTq1,&buffer[34],4,3);
	DoubleToStr(m_dTq1_1,&buffer[38],4,3);
	DoubleToStr(m_dTq2,&buffer[42],4,3);
	DoubleToStr(m_dTq2_1,&buffer[46],4,3);
	DoubleToStr(m_dTq3,&buffer[50],4,3);
	DoubleToStr(m_dTq3_1,&buffer[54],4,3);
	DoubleToStr(m_dVsmax,&buffer[58],4,3);
	DoubleToStr(m_dVcutoff,&buffer[62],4,3);
	DoubleToStr(m_dVslow,&buffer[66],2,2);
	strcpy(&buffer[68],m_strRBName);
	DoubleToStr(m_dRBkV,&buffer[76],4,0);

	return true;
}